﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YmtAuth.Domain.Model.Safe
{
    /// <summary>
    /// 用户登录IP计数器实体
    /// </summary>
    public class UserLoginIpCountEntity
    {
        public class UserLoginIpCountList
        {
            public string Ip { get; private set; }
            public string LoginId { get; private set; }           
            public DateTime CountTimeStart { get; private set; }
            public DateTime CountTimeEnd { get; private set; }
            /// <summary>
            /// success:1,fail :0
            /// </summary>
            public byte LoginSuccess { get; private set; }

            //public string UserType { get; private set; }

            public UserLoginIpCountList(string ip, string loginid)
            {
                this.Ip = ip;
                this.LoginId = loginid;              
                this.CountTimeStart=DateTime.Now;
               
            }

            protected UserLoginIpCountList()
            {

            }
        }

        public string Ip { get; private set; }
        public long Count { get; private set; }
        public DateTime CountBeginTime { get; private set; }
        public DateTime CountEndTime { get; private set; }
        public DateTime LastUpdateTime { get; private set; }
        /// <summary>
        /// success:1,fail :0
        /// </summary>
        public byte LoginSuccess { get; private set; }

        //public string UserType { get; private set; }

        public UserLoginIpCountEntity(string ip,long count,DateTime beginTime,DateTime endTime)
        {
            this.Ip = ip;
            this.Count = count;
            this.CountBeginTime = beginTime;
            this.CountEndTime = endTime;
            this.LastUpdateTime=DateTime.Now;
            //this.UserType = userType;
        }

        public void AddLoginCount(int count = 1)
        {
            this.Count += count;
        }

        public static byte IsSuccess(bool success)
        {
            return success ? (byte)1 : (byte)0;
        }

        public static bool IsSuccess(byte success)
        {
            return success > 0 ? true : false;
        }

        protected UserLoginIpCountEntity()
        {
        }
    }
}
